package mapEditor.map;


//import debug.*;
import mapEditor.MapEditor;
import mapEditor.obj.DrawObject;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;


public class ObjectTableModel extends AbstractTableModel
{ static final long serialVersionUID=0; // AD'HOC

  private Vector<DrawObject> children;
  
  public void edit(int row) { children.elementAt(row).edit(); }
  public void select(int row)
  {	MapEditor.getCurrentMapCanvas().setSelected(children.elementAt(row)); }
  
  public int indexOf(DrawObject obj) { return(children.indexOf(obj)); }


  // *************************************************************************
  // *** CONSTRUCTOR: ObjectTableModel
  // *************************************************************************
  public ObjectTableModel(Vector<DrawObject> children)
  { this.children=children; }

  public int getColumnCount() { return(DrawObject.getFieldNames().length); }
  public String getColumnName(int column) { return(DrawObject.getFieldNames()[column]); }
  public int getRowCount() { return(children.size()); }
  
  public Object getValueAt(int row,int col)
  {	return(children.elementAt(row).getField(col)); }
  
  public void setValueAt(Object value,int row,int col)
  {	children.elementAt(row).setField(col,value);
//    tablePane.updateTable(); // TODO: ?????
//    mapComponent.repaint();
    MapEditor.repaint();
  }
  

  public Class<?> getColumnClass(int c)
  { return getValueAt(0, c).getClass(); }
  
  public boolean isCellEditable(int row, int col)
  { return(getColumnClass(col) == String.class); }
  
}
